package com.platform.comm.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.platform.comm.validation.groups.Modify;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;

import javax.validation.constraints.NotEmpty;
import java.io.Serializable;

/**
 * Description: Id-DTO
 *
 * @author libin Created on 2019/7/20
 **/
public abstract class AbstractQo implements Serializable {

    private static final long serialVersionUID = -7351648129173892245L;

    @NotEmpty(message = "修改时，id不能为空", groups = Modify.class)
    @Getter
    @Setter
    String id;

    /**
     * 初始化数据(默认值设置)
     */
    public abstract void init();

    @Getter
    @Setter
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private int page = 1;
    @Getter
    @Setter
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private int size = 10;
    @JsonIgnore
    public Pageable getPageable() {
        return PageRequest.of(this.page - 1, this.size);
    }
}
